package com.woniuxy.config;

import com.woniuxy.utils.String2Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class MyConvertor implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("statichtml");
    }

    /**
     * 添加我们的自定义的转换器
     * @param registry
//     */
//    @Override
//    public void addFormatters(FormatterRegistry registry) {
//        registry.addConverter(new String2Date());
//    }
//
    /**
     * 把自己写的转换器注册到Spring容器中
     * @return
     */
    @Bean(name = {"datedate","s2d"})  //这个bean的标签，类似之前xml配置中的 <bean id="方法名“  class="return返回的对象">
    public String2Date getString2Date() {
        return new String2Date();
    }
}
